clear
% A = [Inf 3 48 26 23 32;
%      2 Inf 50 28 26 34;
%      34 36 Inf 25 25 23;
%      24 25 24 Inf 37 6;
%      20 21 20 26 Inf 35;
%      26 28 20 5 26 Inf];
A = [Inf, 11, 47, 3, 27, 18;
    9, Inf, 37, 13, 17, 11;
    33, 27, Inf, 50, 21, 36;
    2, 10, 35, Inf, 29, 17;
    19, 14, 15, 21, Inf, 21;
    15, 8, 28, 16, 19, Inf];
A = get_rating(A);
A.where = 1:6;
A.from = 1:6;
A.with = [0;0];
sets = A;
k = 1;

for i = 1:10
    [A1, A2] = get_subset(sets(k))
    if size(A1.ways, 1) == 2,
        break;
    end;
    sets = [sets(1:k-1), A1, A2, sets(k+1:end)];
    [min_r,k] = min([sets.rating])
end;
[i, j] = find(A1.ways == 0);
i = A1.from(i);
j = A1.where(j);
final_way = [A1.with, [i;j]];
get_cycle(final_way(:,2:end));